<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Switch 语句优化</title>
</head>
<body>
    <script>
        // 如果你想优化你的 switch 语句，那么，这个语句会有所帮助。


        //todo:传统方法 Longhand
        switch (data) {
            case 1:
                data1();
                break;
            case 2:
                data2();
                break;
            case 3:
                data();
                break;
            // And so on...
        }
        //todo：优化方法 Shorthand


        function data1() {
            // console.log("data1");
            console.log('%c   data1: ','color: MidnightBlue; background: Aquamarine; font-size: 20px;', );
        }
        function data2() {
            console.log("data2");
        }
        function data() {
            console.log("data");
        }


        var data = {
            1: data1,
            2: data2,
            3: data
        };
        const val = 1
        data[val]();
        // console.log('%c   data[val](): ','color: MidnightBlue; background: Aquamarine; font-size: 20px;', data[val]());


    </script>
</body>
</html>